home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C++ / Applications / PICSee Dust 1.01 / Quaternary Source / GraphicsBufferPriv.h < prev    next >
Text File  |  1995-11-24  |  6KB  |  221 lines

  1. #ifndef GRAPHICSBUFFERPRIV_H_
  2. #define GRAPHICSBUFFERPRIV_H_
  3.  
  4. /*
  5.     GraphicsBufferPriv.h file, Macintosh platform version.
  6.     by Hiep Dam
  7.     Version 4.0
  8.     Last update: Sept 1995
  9.  
  10.  
  11.     This is the header file specific and private to the Macintosh platform
  12.     implementation of GraphicsBuffer. Do not use this file in your own
  13.     applications; use GraphicsBuffer.h instead.
  14. */
  15.  
  16. // ---------------------------------------------------------------------------
  17.  
  18. #define NDEBUG
  19. #include "assert_mac.h"
  20.  
  21. #ifndef __PALETTES__
  22.     #include <Palettes.h>
  23. #endif
  24.  
  25. #ifndef __QDOFFSCREEN__
  26.     #include <QDOffscreen.h>
  27. #endif
  28.  
  29. #ifndef CP_UTILS_H_
  30.     #include "CP_Utils.h"
  31. #endif
  32.  
  33. // ---------------------------------------------------------------------------
  34.  
  35. typedef struct {
  36.     short bufferType;                    // kGraphicsBuffer, kGraphicsEnvironment,
  37.                                         // or kVideoMemoryBuffer
  38.     short bufferFlushedTopLeft;            // true if topleft of global rect is (0,0)
  39.     short bufferCached;
  40.     short bufferDepth;
  41.  
  42.     GWorldPtr gworld;                    // GWorld itself
  43.                                         // (if kVideoMemoryBuffer, this is nil).            
  44.  
  45.     Rect localBounds;                    // Bounds of the gworld, in local coords.
  46.     Rect globBounds;                    // Bounds, in global coords.
  47.     Rect videoBounds;                    // Used only if type == kVideoMemoryBuffer
  48.  
  49.     PixMapHandle pixmap;
  50.     WindowPtr window;
  51.  
  52.     unsigned long realRowBytes;            // (**pixmap).rowBytes & 0x7FFF.
  53.     unsigned long rowBytesDiv4;            // stripRowBytes / 4.
  54.     unsigned long rowBytesDiv2;
  55.     unsigned long *rowAddressOffsets;    // Array of pre-calculated
  56.                                         // rowByte offsets.
  57. } GraphicsBuffer;
  58.  
  59. typedef GraphicsBuffer *GraphicsBufferPrivPtr;
  60.  
  61. // ---------------------------------------------------------------------------
  62.  
  63. /*
  64.     Some useful typedef and defines
  65. */
  66. typedef unsigned char        *OnePixelPtr_8bit,
  67.                             *TwoPixelsPtr_4bit;
  68.  
  69. typedef unsigned short        *PixelPtr_16bit,
  70.                             *TwoPixelsPtr_8bit,
  71.                             *FourPixelsPtr_4bit;
  72.  
  73. typedef unsigned long        *TwoPixelsPtr_16bit,
  74.                             *FourPixelsPtr_8bit,
  75.                             *EightPixelsPtr_4bit;
  76.  
  77. typedef double                *FourPixelsPtr_16bit,
  78.                             *EightPixelsPtr_8bit;
  79.  
  80. // ---------------------------------------------------------------------------
  81.  
  82. #define PtrCopy(s, d) (*(d)++ = *(s)++)
  83. //#define PtrMaskCopy(s, d, m) *(d) &= *(m)++; *(d)++ |= *(s)++
  84. #define PtrMaskCopy(s, d, m) (*(d)++ = (*(d) & *(m)++) | *(s)++)
  85.  
  86. // Some "traditionally faster" shortcuts
  87. #define USE_FASTMATH
  88.  
  89. #if defined(USE_FASTMATH)
  90.     #define FASTDIV2(n) ((n) >> 1L)
  91.     #define FASTDIV4(n) ((n) >> 2L)
  92.     #define FASTDIV8(n) ((n) >> 3L)
  93.     
  94.     #define FASTMULT2(n) ((n) << 1L)
  95.     #define FASTMULT4(n) ((n) << 2L)
  96.     #define FASTMULT8(n) ((n) << 3L)
  97.     
  98.     #define FASTMOD2(n) ((n) & 1L)
  99.     #define FASTMOD4(n) ((n) & 3L)
  100.  
  101. #else
  102.     #define FASTDIV2(n) ((n)/2)
  103.     #define FASTDIV4(n) ((n)/4)
  104.     #define FASTDIV8(n) ((n)/8)
  105.     
  106.     #define FASTMULT2(n) ((n)*2)
  107.     #define FASTMULT4(n) ((n)*4)
  108.     #define FASTMULT8(n) ((n)*8)
  109.     
  110.     #define FASTMOD2(n) ((n)%2)
  111.     #define FASTMOD4(n) ((n)%4)
  112.  
  113. #endif // USE_FASTMATH
  114.  
  115. // ---------------------------------------------------------------------------
  116.  
  117. /* Code switches */
  118.  
  119. // Comment out if you only want to use the C versions, otherwise
  120. // the routines with the 680x0 asm versions will be used.
  121.  
  122. #define USE_ASM68K
  123.  
  124. // Turn off asm usage if compiling for PowerPC...
  125. #if defined(powerc) || defined(__powerc) || defined(POWERPC)
  126. #undef USE_ASM68K
  127. #endif
  128.  
  129. /*
  130.     Comment out if you don't need clipping (you're sure your rect won't
  131.     be out of bounds of the pixmap's boundaries; if so you'll be writing
  132.     to other areas of memory, a dangerous situation).
  133.     Removing the checks should improve the speed however.
  134. */
  135. #define BLIT_CLIPPING
  136.  
  137. /*
  138.     This does automatic offseting if your destination graphicsbuffer
  139.     (kVideoMemoryBuffer) is not flushed topleft at 0,0. You'll want
  140.     to leave this in...
  141. */
  142. #define BLIT_OFFSET
  143.  
  144. /*
  145.     Comment out if you're sure the rects you pass to the blitters
  146.     aren't empty. If they are, the blitters will loop forever!
  147. */
  148. #define BLIT_CHECKEMPTY
  149.  
  150. // ---------------------------------------------------------------------------
  151.  
  152. #ifdef BLIT_CLIPPING
  153.     #define BlitClipBounds(srcRect, destRect, buffer)                        \
  154.         if (destRect.top < buffer->localBounds.top) {                        \
  155.             srcRect.top += buffer->localBounds.top - destRect.top;            \
  156.             destRect.top = buffer->localBounds.top;                            \
  157.             if (destRect.top >= destRect.bottom) return;                    \
  158.         }                                                                    \
  159.         else if (destRect.bottom > buffer->localBounds.bottom) {            \
  160.             srcRect.bottom -= destRect.bottom - buffer->localBounds.bottom; \
  161.             destRect.bottom = buffer->localBounds.bottom;                    \
  162.             if (destRect.bottom <= destRect.top) return;                    \
  163.         }                                                                    \
  164.         if (destRect.left < buffer->localBounds.left) {                        \
  165.             srcRect.left += buffer->localBounds.left - destRect.left;        \
  166.             destRect.left = buffer->localBounds.left;                        \
  167.             if (destRect.left >= destRect.right) return;                    \
  168.         }                                                                    \
  169.         else if (destRect.right > buffer->localBounds.right) {                \
  170.             srcRect.right -= destRect.right - buffer->localBounds.right;    \
  171.             destRect.right = buffer->localBounds.right;                        \
  172.             if (destRect.right <= destRect.left ) return;                    \
  173.         }
  174. #else
  175.     #define BlitClipBounds(srcRect, destRect, buffer)
  176. #endif
  177.  
  178.  
  179. #ifdef BLIT_OFFSET
  180.     #define BlitOffset(destRect, buffer)                                    \
  181.         if (buffer->bufferType == kVideoMemoryBuffer &&                     \
  182.             buffer->bufferFlushedTopLeft == false) {                         \
  183.             FastOffsetRect(destRect, buffer->globBounds.left, buffer->globBounds.top);\
  184.         }
  185. #else
  186.     #define BlitOffset(destRect, buffer)
  187. #endif
  188.  
  189.  
  190. #ifdef BLIT_CHECKEMPTY
  191.     #define CheckEmptyRect(destRect)                \
  192.         if (destRect.right <= destRect.left ||        \
  193.             destRect.bottom <= destRect.top) return
  194. #else
  195.     #define CheckEmptyRect(destRect)
  196. #endif
  197.  
  198. // ---------------------------------------------------------------------------
  199.  
  200. // Related to the blitters only.
  201. extern SignedByte    gMMUMode;
  202. extern Boolean        gNotIn32Mode;
  203.  
  204. /*
  205.     Blitting info; only routines that have both a C and 680x0 asm version
  206.     uses this structure. Eventually I'll have all the pixel copying routines
  207.     using this. This structure is long-word aligned for maximum efficiency
  208.     on both 68K and PPC architectures.
  209. */
  210.  
  211. typedef struct {
  212.     CP_ULong widthChunksToCopy;
  213.     CP_ULong srcRowOffset;
  214.     CP_ULong destRowOffset;
  215.     CP_ULong rowsToCopy;
  216.     CP_ULong destMem;
  217.     CP_ULong srcMem;                // typecast to char*, short*, or long*
  218. } BlitInfo;
  219. extern BlitInfo mBlitInfo;
  220.  
  221. #endif // GRAPHICSBUFFERPRIV_H_